package cn.stylefeng.guns.unitl;


import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import java.io.Serializable;

@Data
public class ResponseMsg implements Serializable {


    private static final long serialVersionUID = 1L;

    /** 错误码 **/
    private Integer status;

    /** 错误描述 **/
    private String desc;

    /** 响应数据 **/
    private Object result;


    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object data) {
        this.result = data;
    }


    public ResponseMsg() {
        status = 10001;
        desc = "";
    }

    public ResponseMsg(Integer status, String desc) {
        this.status = status;
        this.desc = desc;
    }

    @JsonIgnore
    public void setResponseSuccess(Object data) {
        this.status = 10001;
        this.desc = "操作成功";
        this.result = data;
    }

    @JsonIgnore
    public void setResponseSuccess(SysErrorCode sysErrorCode,Object data) {
        this.status = sysErrorCode.getCode();
        this.desc = sysErrorCode.getDesc();
        this.result = data;
    }

    @JsonIgnore
    public void setResponseSuccess(String desc) {
        this.status = 10001;
        this.desc = desc;
        this.result = "";
    }

    @JsonIgnore
    public void setResponseSuccess(String desc,Object data) {
        this.status = 10001;
        this.desc = desc;
        this.result = data;
    }

    @JsonIgnore
    public ResponseMsg(IErrorCode code) {
        this.status = code.getCode();
        this.desc = code.getDesc();
    }

    @JsonIgnore
    public void setResponseError(IErrorCode code) {
        this.status = code.getCode();
        this.desc = code.getDesc();
        this.result = "fail";
    }

    @JsonIgnore
    public void setResponseSuccess(IErrorCode code) {
        this.status = code.getCode();
        this.desc = code.getDesc();
    }





    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }








}
